#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <stdio.h>

const int BUF_SIZE = 1024;

int main()
{
    int sock;
    sockaddr_in addr;
    char buf[BUF_SIZE];
    int bytes_read;

    sock = socket(AF_INET, SOCK_DGRAM, 0);
    if(sock < 0)
    {
        perror("Unable to create socket");
        return 1;
    }

    addr.sin_family = AF_INET;
    addr.sin_port = htons(6001);
    addr.sin_addr.s_addr = htonl(INADDR_ANY);
    if(bind(sock, (sockaddr *)&addr, sizeof(addr)) < 0)
    {
        perror("Unable to bind socket");
        return 1;
    }

    while(true)
    {
        printf("500");
        sockaddr_in client_addr;
        socklen_t len = sizeof(sockaddr_in);
        bytes_read = recvfrom(sock, buf, BUF_SIZE, 0, (sockaddr *)&client_addr, &len);
        sendto(sock, buf, bytes_read, 0, (sockaddr *)&client_addr, len);
    }

    return 0;
}
